#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
typedef pair<int, int> PI;
vector<PI> st;
i64 n, m, ans, x, val, val2, k, b, c1, c2, l = -2000000000;
void solve() {
	cin >> n >> m; k = m - n;
    st.reserve(n + m + 1);
    st.push_back({-l, 0});
    while (n--) {
        cin >> x; b += x;
        st.push_back({x, 2});
    }
    while (m--) {
        cin >> x; b -= x;
        st.push_back({x, -2});
    }
    ans = l; val = abs(k * l + b);
    sort(st.begin(), st.end());
    for (auto &[r, x] : st) {
        if (k != 0) {
            c1 = -b / k;
            for (int i = -1; i <= 1; ++i) {
                c2 = c1 + i;
                if (c2 < l) c2 = l;
                if (c2 > r) c2 = r;
                val2 = abs(k * c2 + b);
                if (val2 < val) ans = c2, val = val2;
            }
        }
        k += x; b -= x * r; l = r;
    } cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int _ = 1;
    // std::cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

